package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.User;
import com.soft.entity.Worker;
@SpringBootTest
public class WorkerMapperTest {
	@Autowired
	private WorkerMapper workerMapper;
	//@Test
	public void testSelect() {
		List<Worker> workerList=workerMapper.selectList(null);
		for(int i=0;i<workerList.size();i++) {
			System.out.print(workerList.get(i).getWorkerId());
			System.out.print(workerList.get(i).getWorkerName()+" ");
			System.out.print(workerList.get(i).getWorkerSex()+" ");
			System.out.print(workerList.get(i).getWorkerPhone()+" ");
			
		}
	}
	
	@Test
	public void selectIdTest() {
		Worker worker = workerMapper.selectById(3);
		System.out.println(worker.getWorkerName());
	}
	
	@Test
	public void selectOneTest() {
		QueryWrapper<Worker> qw = new QueryWrapper<>();
		qw.gt("worker_name", 1);
		try {
		Worker worker = workerMapper.selectOne(qw);
		System.out.println(worker.getWorkerName());
		}catch(Exception e) {
			System.out.println("有重复，请修改");
		}
	}
	
	//@Test
	public void updateTest() {
		Worker worker = new Worker();
		worker.setWorkerId(1l);
		worker.setWorkerName("杨总燃");
		worker.setWorkerSex("人");
		worker.setWorkerPhone("6666");
		workerMapper.updateById(worker);	
	}
	
	
	//@Test
	public void updateQueryTest() {
		UpdateWrapper<Worker> uw = new UpdateWrapper<>();
		uw.gt("worker_id","2");
		Worker worker = new Worker();
		worker.setWorkerSex("人类");
		workerMapper.update(worker,uw);
	}
	
	//@Test
	public void deleteTest() {
		Worker worker = new Worker();
		worker.setWorkerId(2l);
		workerMapper.deleteById(worker);
	}
	//@Test
	public void insertTest() {
		Worker worker = new Worker();
		worker.setWorkerName("几脏");
		worker.setWorkerSex("女");
		worker.setWorkerPhone("452");
		workerMapper.insert(worker);
	}

	//@Test
	public void deleteQueryTest() {
		QueryWrapper<Worker> qw = new QueryWrapper<>();
		qw.eq("worker_name","几脏");
		workerMapper.delete(qw);
	}
}
